<template>
    <div class="memu-main" ref="target">
      <div v-for="(item, index) in items" :key="index" class="menu-item">{{ item }}</div>
      <button @click="rightClicMoveUpHanlder('up')">上移</button>
      <button @click="rightClicMoveUpHanlder('down')">下移</button>
      <button @click="rightClicMoveUpHanlder('upBest')">置顶</button>
      <button @click="rightClicMoveUpHanlder('downBest')">置顶</button>
      <button @click="copyHanlder">复制</button>
      <button @click="deleteHanlder">删除</button>
      <img class="close" src="@/assets/image/icon/close.png" alt="" @click="closeHanlder">
    </div>
</template>

<script setup>
import {defineEmits, ref} from 'vue'
import { onClickOutside } from '@vueuse/core'
const emits = defineEmits(['close', 'delete', 'copy', 'changeHierarchy'])
const items = ["选项 1", "选项 2", "选项 3"]
const target = ref(null)
// 关闭
const closeHanlder = ()=> {
    emits('close')
}
// 上移 下移 置顶 置底
const rightClicMoveUpHanlder = (type) => {
  emits('changeHierarchy',type)
  // 删除后同时关闭弹窗
  closeHanlder()
}
// 删除
const deleteHanlder = () => {
  emits('delete')
  // 删除后同时关闭弹窗
  closeHanlder()
}
// 复制
const copyHanlder = ()=> {
  emits('copy')
  // 删除后同时关闭弹窗
  closeHanlder()
}
onClickOutside(target, (event) => closeHanlder())
</script>
<style lang="scss" scoped>
.memu-main{
  width: 100px;
  background-color: #fff;
  padding: 10px;
  border-radius: 5px;
  box-shadow: 0 5px 20px rgba(0,0,0,0.1);
  position: absolute;
  left: 0;
  top: 0;
  z-index: 99;
  padding-bottom: 10px;
}
.memu-main .menu-item{
  list-style-type: none;
  padding: 5px;
  background-color: #fff;
  border-radius: 5px;
  cursor: pointer;
}
.memu-main .menu-item:hover{
  background-color: cornflowerblue;
  color: #fff;
}
.close{
  width: 15px;
  position: absolute;
  top: 8px;
  right: 8px;
  cursor: pointer;
}
</style>